import gevent
import time
# from gevent import monkey
# monkey.patch_all()
def write():
    print("在写作业")
    gevent.sleep(1) # 自动切换(遇到休眠进到了阻塞状态，会执行其他的子程序)
    # time.sleep(1)
    print("写完了")

def watch():
    print("在看电视")
    gevent.sleep(1)
    # time.sleep(1)
    print("停电了")

# g1 = gevent.spawn(write)
# g2 = gevent.spawn(watch)
# g1.join()
# g2.join()
gevent.joinall([
    gevent.spawn(write),
    gevent.spawn(watch)
])

# gevent模块sleep()
# time模块sleep()
"""
gevent模块只能只能自己的sleep，time.sleep()识别不了，所以就做不到自动切换的效果

打补丁：
from gevent import monkey
monkey.patch_all()
"""
